package org.osflash.signals.natives.base;

import asunit.asserts.AssertEquals;
import asunit.asserts.AssertSame;
import asunit.asserts.AssertTrue;
import asunit.framework.IAsync;
import org.osflash.signals.natives.sets.InteractiveObjectSignalSet;
import flash.events.MouseEvent;

class SignalSpriteTest {

	@:meta(Inject())
	public var async : IAsync;
	var sprite : SignalSprite;
	@:meta(Before())
	public function setUp() : Void {
		sprite = new SignalSprite();
	}

	@:meta(After())
	public function tearDown() : Void {
		sprite.signals.removeAll();
		sprite = null;
	}

	@:meta(Test())
	public function has_signals_after_creation() : Void {
		assertTrue(Std.is(sprite.signals, InteractiveObjectSignalSet));
	}

	@:meta(Test())
	public function numListeners_is_0_after_creation() : Void {
		assertEquals(sprite.signals.numListeners, 0);
	}

	@:meta(Test())
	public function signal_add_then_EventDispatcher_dispatch_should_call_signal_listener() : Void {
		sprite.signals.click.add(async.add(checkClickEvent));
		sprite.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
	}

	function checkClickEvent(event : MouseEvent) : Void {
		assertSame(MouseEvent.CLICK, event.type);
		assertSame(sprite, event.target);
	}

}

